/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode *detectCycle(struct ListNode *head) {
    //判断有没有环
    struct ListNode* fast = head,*slow = head;
    while(fast&&fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
        if(fast == slow)//有环
        {
            struct ListNode* meet = fast;
            struct ListNode* cur = head;
            while(meet!=cur)
            {
                meet=meet->next;
                cur = cur->next;
            }
            return meet;
        }
    }
    return NULL;
}